//------------------------------------------------------------------------------
// <copyright file="WebDataService.svc.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using NCT.MRS.DataAccessLayer;
using NCT.MRS.DataAccessLayer.Entities;
using NCT.MRS.DataAccessLayer.Repositories;

namespace NCT.MRS.WebServiceLayer
{
    public partial class MrsDataService : DataService<AppContext>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            config.UseVerboseErrors = true;
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("GetAllAccessTypesBySection", ServiceOperationRights.All);

        }

        protected override AppContext CreateDataSource()
        {
            var appcontext = new AppContext();
            return appcontext;
        }

        [WebGet]
        public IQueryable<AccessSection> GetAllAccessTypesBySection()
        {
            AccessSectionRepository repo = new AccessSectionRepository(this.CurrentDataSource);
            return repo.GetAll().AsQueryable();
        }
    }
}
